import { requestClient } from '#/api/request';
import type { IOutDto, IInDto } from '#/utils/daprplus';

export interface RoleOutDto extends IOutDto {
  name?: string;
  remark?: string;
  isAdmin?: boolean;
  isDefault?: boolean;
  isLocked?: boolean;
  createdTime?: Date;
}

export interface RoleInDto extends IInDto {
  name: string;
  remark?: string;
  isAdmin: boolean;
  isDefault: boolean;
  isLocked: boolean;
}

export interface RoleNodeDto {
  id: string;
  name: string;
  isSelected: boolean;
}

/**
 * 获取角色节点
 * @param userId 可选的用户ID，如果提供则会标记用户已有的角色
 * @param urlPrefix 服务地址前缀
 * @returns 角色节点列表
 */
export async function getRoleNodeApi(userId?: string) {
  const url = `/identity/api/role/node${userId ? `?userId=${userId}` : ''}`;
  const result = await requestClient.get<RoleNodeDto[]>(url, {
    responseReturn: 'data',
  });
  return result;
}
